/* eslint-disable vue/comment-directive */
<template>
  <div class="department-container">
    <div class="app-container">
      <PageTools>
        <template #left>
          <span>总记录数:{{ total }} 条</span>
        </template>
        <template #right>
          <el-button type="warning">导入Excel</el-button>
          <el-button type="danger">导出Excel</el-button>
          <el-button type="primary" @click="doAdd">新增员工</el-button>
        </template>
      </PageTools>
      <el-card style="margin-top: 10px">
        <el-table border :data="list">
          <el-table-column label="序号" type="index" />
          <el-table-column label="姓名" prop="username" />
          <el-table-column label="工号" prop="workNumber" />
          <el-table-column label="聘用形式" prop="formOfEmployment" />
          <el-table-column label="部门" prop="departmentName" />
          <el-table-column label="入职时间" prop="timeOfEntry" />
          <el-table-column label="操作" width="280">
            <template>
              <el-button type="text" size="small">查看</el-button>
              <el-button type="text" size="small">分配角色</el-button>
              <el-button type="text" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <el-row
          type="flex"
          justify="center"
          align="middle"
          style="height: 60px"
        >
          <el-pagination layout="prev, pager, next" />
        </el-row>
      </el-card>
      <el-dialog :visible.sync="showDialog" title="新增员工">
        <DIALOG />
      </el-dialog>
    </div>
  </div>
</template>
<script>
import PageTools from '@/components/PageTools/index.vue'
import DIALOG from './employeesDidlog.vue'
import { getEmployeeList } from '@/api/employees'
export default {
  // 注册组件
  components: {
    PageTools,
    DIALOG
  },
  data() {
    return {
      showDialog: false,
      list: [], // 渲染列表
      total: 0
    }
  },
  created() {
    this.loadEmployeeList()
  },
  methods: {
    doAdd() {
      this.showDialog = true
    },
    async loadEmployeeList() {
      const res = await getEmployeeList()
      console.log(res)
      this.list = res.data.rows
      this.total = res.data.total
    }
  }
}
</script>
